﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using CrmContacto.Contracts.Contracts;
using Web.Framework.Svc;

namespace CrmContacto.Contracts
{
    [Serializable]
    [DataContract]
    public class Cliente : IAuditable
    {
        public Cliente()
        {           
            Categorias = new List<MaestroBase>();
            Ventas = new List<ClienteVenta>();
            Bitacora = new List<ClienteBitacora>();
            ListasDeDistribucion = new List<ListaDeDistribucion>();
        }

        [DataMember]
        public int Id { get; set; }

        [DataMember]
        public int? OrigenPuntoDeVentaId { get; set; }

        [DataMember]
        public string UserName { get; set; }

        [DataMember]
        public int EmpresaId { get; set; }

        [DataMember]
        public int? TipoDocumentoId { get; set; }

        [DataMember]
        public string TipoDocumento { get; set; }

        [DataMember]
        public decimal? Dni { get; set; }

        [DataMember]
        public string Email { get; set; }

        [DataMember]
        public string Nombre { get; set; }

        [DataMember]
        public string Apellido { get; set; }

        [DataMember]
        public short? CumpleDia { get; set; }

        [DataMember]
        public short? CumpleMes { get; set; }

        [DataMember]
        public short? CumpleAnio { get; set; }

        [DataMember]
        public int? NacionalidadId { get; set; }

        [DataMember]
        public string Domicilio { get; set; }

        [DataMember]
        public string CodigoPostal { get; set; }

        [DataMember]
        public int? ProvinciaId { get; set; }

        [DataMember]
        public int? EstadoEmail { get; set; }

        [DataMember]
        public int? Estado { get; set; }

        [DataMember]
        public string NroCredencial { get; set; }

        [DataMember]
        public string Telefono { get; set; }

        [DataMember]
        public DateTime? FechaUltimaCompra { get; set; }             

        [DataMember]
        public List<MaestroBase> Categorias { get; set; }

        [DataMember]
        public List<ClienteVenta> Ventas { get; set; }

        [DataMember]
        public List<ClienteBitacora> Bitacora { get; set; }

        [DataMember]
        public List<ListaDeDistribucion> ListasDeDistribucion { get; set; }

        [DataMember]
        public int OrigenId { get; set; }

        [DataMember]
        public bool DeseaRecibirEmails { get; set; }

        [DataMember]
        public int? Sexo { get; set; }

        [DataMember]
        public int? CantidadHijos { get; set; }

        [DataMember]
        public int? EdadHijoMenor { get; set; }

        [DataMember]
        public DateTime AuditFechaCreacion { get; set; }

        [DataMember]
        public string AuditUserNameCreacion { get; set; }

        [DataMember]
        public DateTime? AuditFechaModificacion { get; set; }

        [DataMember]
        public string AuditUserNameModificacion { get; set; }

        public string CategoriasDisplay
        {
            get
            {
                StringBuilder b = new StringBuilder();
                string separador = string.Empty;

                foreach (var cat in this.Categorias)
                {
                    b.Append(separador);
                    separador = ", ";
                    b.Append(cat.Nombre);
                }

                return b.ToString();                                
            }
        }
    }
}
